#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    string inp;
    cin>>inp;
    int cnt=0;
    for(int i=0;i<inp.length();i++){
        if(inp[i]=='T'){cnt++;}
    }
    int tcount=cnt;
    int pcount=0;
    int result=0;
    for(int i=0;i<inp.length();i++){
        if(inp[i]=='P'){pcount++;}
        if(inp[i]=='T'){tcount--;}
        if(inp[i]=='A'){
            result+=pcount*tcount;
            result%=1000000007;
        }
    }
    printf("%d\n",result);

}
